package com.educate.member.web.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.educate.common.web.R;
import com.educate.device.model.bo.MemberBO;
import com.educate.member.rpc.api.MemberService;
import lombok.extern.log4j.Log4j2;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Log4j2
@RestController
@RequestMapping("member")
public class MemberController {

    @Reference(version = "${api.service.version}",
            application = "${dubbo.application.id}",
            url = "${dubbo.application.url}")
    private MemberService memberService;

    @PostMapping(value = "/create")
    public R create(@RequestBody MemberBO bo) {
        memberService.create(bo);
        return R.ok();
    }

    @PostMapping(value = "/delete")
    public R delete(@RequestBody MemberBO bo) {
        memberService.delete(bo);
        return R.ok();
    }

    @PostMapping(value = "/delete/{courtId}")
    public R delete(@PathVariable String courtId) {
        memberService.delete(courtId);
        return R.ok();
    }

    @PostMapping(value = "/detail/{courtId}")
    public R<MemberBO> detail(@PathVariable String courtId) {
        MemberBO bo = memberService.detail(courtId);
        return R.ok(bo);
    }

    @PostMapping(value = "/detail")
    public R<MemberBO> detail(@RequestBody MemberBO bo) {
        MemberBO detail = memberService.detail(bo);
        return R.ok(detail);
    }

    @PostMapping(value = "/update")
    public R<MemberBO> update(@RequestBody MemberBO bo) {
        memberService.update(bo);
        return R.ok();
    }

    @PostMapping(value = "/query")
    public R<Page<MemberBO>> query(@RequestBody MemberBO bo) {
        Page<MemberBO> result = memberService.query(bo, bo.pageable());
        return R.ok(result);
    }

    @PostMapping(value = "/list")
    public R<List<MemberBO>> list(@RequestBody MemberBO bo) {
        List<MemberBO> result = memberService.list(bo);
        return R.ok(result);
    }

}
